package com.study.spring.stopWatch;

import org.springframework.util.StopWatch;

/**
 * @author
 * @date 2021年11月26日 23:22
 * @description
 */
public class SpringStopWatchExample {


    public static void main(String[] args) throws InterruptedException {
        StopWatch stopWatch = new StopWatch();

        //1.普通使用
        stopWatch.start();

        Thread.sleep(1000);

        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());

        stopWatch.start("A");

        Thread.sleep(1000);

        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());


        stopWatch.start("A");
        Thread.sleep(500);
        stopWatch.stop();
        stopWatch.start("B");
        Thread.sleep(300);
        stopWatch.stop();
        stopWatch.start("C");
        Thread.sleep(200);
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());
        System.out.println("-----------------------");
        System.out.println(stopWatch.shortSummary());
        System.out.println("-----------------------");
        System.out.println(stopWatch.getTaskCount());
        System.out.println("-----------------------");
        System.out.println(stopWatch.getLastTaskInfo().getTaskName());


//        getTotalTimeSeconds() 获取总耗时秒，同时也有获取毫秒的方法
//        prettyPrint() 优雅的格式打印结果，表格形式
//        shortSummary() 返回简短的总耗时描述
//        getTaskCount() 返回统计时间任务的数量
//        getLastTaskInfo().getTaskName() 返回最后一个任务TaskInfo对象的名称

    }
}
